package cn.wbnull.springbootdemo.io;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;

/**
 * 功能描述
 *
 * @author EDZ
 * @since 2022-09-01
 */
class BiaMaSuaFa {
    public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        byte[] input = new byte[] { (byte) 0xe4, (byte) 0xb8, (byte) 0xad };
        String s1 = Base64.getEncoder().encodeToString(input);
        System.out.println(s1);
//        String s = URLEncoder.encode("%E4%B8%AD%E6%96%87%21", String.valueOf(StandardCharsets.UTF_8));
//        System.out.println(s);
        //解码base编码
        byte[] bytes = Base64.getDecoder().decode("5Lit");
        System.out.println(Arrays.toString(bytes));

        System.out.println("=============================================");
        MessageDigest md5 = MessageDigest.getInstance("SHA-1");
        md5.update("hello".getBytes(StandardCharsets.UTF_8));
        md5.update("word".getBytes(StandardCharsets.UTF_8));
        byte[] digest = md5.digest();
        System.out.println(new BigInteger(1,digest).toString(16));
    }
}
